<?php
/* *
 * 功能：用户列表
 * 日期：2016-02-17
 * 源码来自：资源e站（Zye.cc）
 */
?>
<?php
$mod='blank';
include("../includes/common.php");
$title='用户列表';
$plus = true;
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <nav class="navbar navbar-fixed-top navbar-default">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">导航按钮</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="./">后台管理</a>
      </div><!-- /.navbar-header -->
      <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="./"><span class="glyphicon glyphicon-user"></span> 平台首页</a>
          </li>
		  <li>
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cloud"></span> 卡密管理<b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="./kmlist.php">卡密列表</a></li>
			  <li><a href="./search.php">搜索卡密</a><li>
            </ul>
          </li>
		  <li><a href="./log.php"><span class="glyphicon glyphicon-calendar"></span> 日志查看</a></li>
		  <li><a href="../"><span class="glyphicon glyphicon-home"></span> 返回首页</a></li>
          <?php require_once('nav.php'); ?><li><a href="./login.php?logout"><span class="glyphicon glyphicon-log-out"></span> 退出登录</a></li>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container -->
  </nav><!-- /.navbar -->
  <div class="container" style="padding-top:70px;">
    <div class="col-sm-12 col-md-10 center-block" style="float: none;">
<?php
if($my=='del'){
echo '<div class="panel panel-primary">
<div class="panel-heading w h"><h3 class="panel-title">删除用户</h3></div>
<div class="panel-body box">';
$id=$_GET['id'];
$sql=$DB->query("DELETE FROM tell_users WHERE id='$id'");
if($sql){echo '删除成功！';}
else{echo '删除失败！';}
echo '<hr/><a href="./ulist.php">>>返回用户列表</a></div></div>';
}

elseif($my=='qk'){//清空用户
echo '<div class="panel panel-primary">
<div class="panel-heading w h"><h3 class="panel-title">清空用户</h3></div>
<div class="panel-body box">
您确认要清空所有用户吗？清空后无法恢复！<br><a href="./ulist.php?my=qk2">确认</a> | <a href="javascript:history.back();">返回</a></div></div>';
}
elseif($my=='qk2'){//清空用户结果
echo '<div class="panel panel-primary">
<div class="panel-heading w h"><h3 class="panel-title">清空用户</h3></div>
<div class="panel-body box">';
if($DB->query("DELETE FROM tell_users")==true){
echo '<div class="box">清空成功.</div>';
}else{
echo'<div class="box">清空失败.</div>';
}
echo '<hr/><a href="./ulist.php">>>返回用户列表</a></div></div>';
}elseif($my == 'edit'){
	$id = $_GET['id'];
	if(!$row = $DB->get_row("select * from tell_users where id='{$id}' limit 1")){
		exit("<script>alert('该用户不存在');history.go(-1);</script>");
		}
	if($_POST['type'] == "xgzl"){
		$vip = $_POST['vip'];
		$agent = $_POST['agent'];
		$money = is_numeric($_POST['money'])?$_POST['money']:0;
		$sql = "update tell_users set vip='$vip',agent='$agent',money='$money' where id='$id' limit 1";
		if($DB->query($sql)){
			exit("<script>alert('修改成功');history.go(-1);</script>");
			}else{
				exit("<script>alert('修改失败');history.go(-1);</script>");
				}
	}

?>
     <div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title"><?=$row['phone']?>资料修改</h3></div>
        <div class="panel-body">
          <form action="?my=edit&id=<?=$id?>" method="post" class="form-horizontal" role="form">
          <input type="hidden" name="type" value="xgzl" />
          	<div class="input-group">
              <span class="input-group-addon">是否VIP</span>
			  <select name="vip" class="form-control">                  
                <option value="0">0_否</option>
                <option value="1" <?=$row['vip']?"selected":''?> >1_是</option>
				</select>
            </div><br/>
            <div class="input-group">
              <span class="input-group-addon">代理级别</span>
			  <select name="agent" class="form-control">                  
                <option value="0" >0_不是代理</option>
                <?php 
										 $ne = $DB->query("select * from tell_level ");
										 while($shop_type = $DB->fetch($ne)){
										 ?>
                                          <option value="<?=$shop_type['id']?>" <?=$row['agent']==$shop_type['id']?"selected":''?>><?=$shop_type['name']?></option>
                                          <?php } ?>
				</select>
            </div><br/>
            <div class="input-group">
              <span class="input-group-addon">余额</span>
			  <input type="text" name="money" value="<?=$row['money']?>" class="form-control">
            </div><br/>
            
            <div class="form-group">
              <div class="col-sm-12"><input type="submit" name="submit" value="修改" class="btn btn-primary form-control"/></div>
            </div>
          </form>
        </div>
      </div>  
        
<?php
	
	}
else
{

echo '<form action="ulist.php?my=add" method="POST" class="form-inline">
  <a href="ulist.php?my=qk" class="btn btn-danger">清空所有用户</a>
</form>';

if(isset($_GET['kw'])) {
	if($_GET['type']==1) {
		$sql=" `km`='{$_GET['kw']}'";
		$numrows=$DB->count("SELECT count(*) from tell_users WHERE{$sql}");
		$con='包含 '.$_GET['kw'].' 的共有 <b>'.$numrows.'</b> 个用户';
	}elseif($_GET['type']==2) {
		$sql=" `user`='{$_GET['kw']}'";
		$numrows=$DB->count("SELECT count(*) from tell_users WHERE{$sql}");
		$con='包含 '.$_GET['kw'].' 的共有 <b>'.$numrows.'</b> 个用户';
	}
}else{
	$numrows=$DB->count("SELECT count(*) from tell_users WHERE 1");
	$sql=" 1";
	$con='平台共有 <b>'.$numrows.'</b> 个用户';
}
echo $con;
?>
      <div class="table-responsive">
        <table class="table table-striped">
          <thead><tr><th>手机号</th><th>密码</th><th>用户组</th><th>代理级别</th><th>注册时间</th><th>操作</th></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM tell_users WHERE{$sql} order by id desc limit $offset,$pagesize");
while($res = $DB->fetch($rs))
{
	if($res['agent']){
		$dlname = $DB->get_row("select * from tell_level where id='{$res['agent']}' limit 1");
		}
?>
<tr>
<td><?=$res['phone']?></td>
<td><?=$res['pass']?></td>
<td><?=$res['vip']?"<font color='red'>VIP</font>":"不是VIP"?></td>
<td><?=$res['agent']?"<font color='red'>".$dlname['name']."</font>":"不是代理"?></td>
<td><?=$res['regtime']?></td>
<td><a href="ulist.php?my=del&id=<?=$res['id']?>" class="label label-danger">删除</a><a href="ulist.php?my=edit&id=<?=$res['id']?>" class="label label-warning">修改</a></td>
</tr>
<?php
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="ulist.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="ulist.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="ulist.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="ulist.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="ulist.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="ulist.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
}
?>
    </div>
  </div>